package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.CmsTopic;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.CmsTopicDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface CmsTopicMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn
            .columnList(id, categoryId, name, createTime, startTime, endTime, attendCount, attentionCount, readCount, awardName, attendType, content);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(CmsTopic record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(categoryId).equalTo(record::getCategoryId)
                  .set(name).equalTo(record::getName)
                  .set(createTime).equalTo(record::getCreateTime)
                  .set(startTime).equalTo(record::getStartTime)
                  .set(endTime).equalTo(record::getEndTime)
                  .set(attendCount).equalTo(record::getAttendCount)
                  .set(attentionCount).equalTo(record::getAttentionCount)
                  .set(readCount).equalTo(record::getReadCount)
                  .set(awardName).equalTo(record::getAwardName)
                  .set(attendType).equalTo(record::getAttendType)
                  .set(content).equalTo(record::getContent);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(CmsTopic record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(categoryId).equalToWhenPresent(record::getCategoryId)
                  .set(name).equalToWhenPresent(record::getName)
                  .set(createTime).equalToWhenPresent(record::getCreateTime)
                  .set(startTime).equalToWhenPresent(record::getStartTime)
                  .set(endTime).equalToWhenPresent(record::getEndTime)
                  .set(attendCount).equalToWhenPresent(record::getAttendCount)
                  .set(attentionCount).equalToWhenPresent(record::getAttentionCount)
                  .set(readCount).equalToWhenPresent(record::getReadCount)
                  .set(awardName).equalToWhenPresent(record::getAwardName)
                  .set(attendType).equalToWhenPresent(record::getAttendType)
                  .set(content).equalToWhenPresent(record::getContent);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<CmsTopic> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("CmsTopicResult")
    Optional<CmsTopic> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "CmsTopicResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "category_id", property = "categoryId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "start_time", property = "startTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "end_time", property = "endTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "attend_count", property = "attendCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "attention_count", property = "attentionCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "read_count", property = "readCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "award_name", property = "awardName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "attend_type", property = "attendType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<CmsTopic> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, cmsTopic, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, cmsTopic, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(CmsTopic record) {
        return MyBatis3Utils.insert(this::insert, record, cmsTopic, c ->
                c.map(categoryId).toProperty("categoryId")
                 .map(name).toProperty("name")
                 .map(createTime).toProperty("createTime")
                 .map(startTime).toProperty("startTime")
                 .map(endTime).toProperty("endTime")
                 .map(attendCount).toProperty("attendCount")
                 .map(attentionCount).toProperty("attentionCount")
                 .map(readCount).toProperty("readCount")
                 .map(awardName).toProperty("awardName")
                 .map(attendType).toProperty("attendType")
                 .map(content).toProperty("content")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(CmsTopic record) {
        return MyBatis3Utils.insert(this::insert, record, cmsTopic, c ->
                c.map(categoryId).toPropertyWhenPresent("categoryId", record::getCategoryId)
                 .map(name).toPropertyWhenPresent("name", record::getName)
                 .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
                 .map(startTime).toPropertyWhenPresent("startTime", record::getStartTime)
                 .map(endTime).toPropertyWhenPresent("endTime", record::getEndTime)
                 .map(attendCount).toPropertyWhenPresent("attendCount", record::getAttendCount)
                 .map(attentionCount).toPropertyWhenPresent("attentionCount", record::getAttentionCount)
                 .map(readCount).toPropertyWhenPresent("readCount", record::getReadCount)
                 .map(awardName).toPropertyWhenPresent("awardName", record::getAwardName)
                 .map(attendType).toPropertyWhenPresent("attendType", record::getAttendType)
                 .map(content).toPropertyWhenPresent("content", record::getContent)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<CmsTopic> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, cmsTopic, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<CmsTopic> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, cmsTopic, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<CmsTopic> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, cmsTopic, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<CmsTopic> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, cmsTopic, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(CmsTopic record) {
        return update(c ->
                c.set(categoryId).equalTo(record::getCategoryId)
                 .set(name).equalTo(record::getName)
                 .set(createTime).equalTo(record::getCreateTime)
                 .set(startTime).equalTo(record::getStartTime)
                 .set(endTime).equalTo(record::getEndTime)
                 .set(attendCount).equalTo(record::getAttendCount)
                 .set(attentionCount).equalTo(record::getAttentionCount)
                 .set(readCount).equalTo(record::getReadCount)
                 .set(awardName).equalTo(record::getAwardName)
                 .set(attendType).equalTo(record::getAttendType)
                 .set(content).equalTo(record::getContent)
                 .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(CmsTopic record) {
        return update(c ->
                c.set(categoryId).equalToWhenPresent(record::getCategoryId)
                 .set(name).equalToWhenPresent(record::getName)
                 .set(createTime).equalToWhenPresent(record::getCreateTime)
                 .set(startTime).equalToWhenPresent(record::getStartTime)
                 .set(endTime).equalToWhenPresent(record::getEndTime)
                 .set(attendCount).equalToWhenPresent(record::getAttendCount)
                 .set(attentionCount).equalToWhenPresent(record::getAttentionCount)
                 .set(readCount).equalToWhenPresent(record::getReadCount)
                 .set(awardName).equalToWhenPresent(record::getAwardName)
                 .set(attendType).equalToWhenPresent(record::getAttendType)
                 .set(content).equalToWhenPresent(record::getContent)
                 .where(id, isEqualTo(record::getId))
        );
    }
}
